home *** CD-ROM | disk | FTP | other *** search
/ Cracking 1 / Cracking I..iso / Tools / Ostatní / aPLib v0.26b / examples / ada / aplib.adb < prev    next >
Encoding:
Text File  |  2001-12-15  |  1.7 KB  |  53 lines

  1. -----------------------------------------------------------------------------
  2. --  File: aplib.adb; see specification (aplib.ads)
  3. -----------------------------------------------------------------------------
  4.  
  5. package body aPLib is
  6.  
  7.   type byte is mod 2 ** 8; for byte'size use 8;
  8.   type t_byte_array is array(integer range <>) of byte;
  9.   type p_byte_array is access t_byte_array;
  10.   buffer: p_byte_array:= new t_byte_array(1..640_000);
  11.  
  12.   procedure Pack(source: unpacked_data;
  13.                  destination: out packed_data;
  14.                  packed_length: out integer) is
  15.  
  16.     type p_cb is access function (unpacked, packed: integer) return integer;
  17.  
  18.     function aP_pack(source: unpacked_data;
  19.                      destination: packed_data;
  20.                      length: integer;
  21.                      buffer: t_byte_array;
  22.                      cb: p_cb)
  23.         return integer;
  24.      pragma Import(C, aP_pack, "aP_pack");
  25.  
  26.     function cb(unpacked, packed: integer) return integer is
  27.       cont: boolean;
  28.       begin
  29.         Call_back(unpacked, packed, cont);
  30.         if cont then return 1; else return 0; end if;
  31.       end;
  32.     p: p_cb:= cb'access;
  33.  
  34.     begin
  35.       packed_length:= 
  36.         aP_pack(source, destination, source'size / 8, buffer.all, p);
  37.       if packed_length=0 then raise pack_failed; end if;
  38.     end Pack;
  39.  
  40.   procedure Depack(source: packed_data; destination: out unpacked_data) is
  41.  
  42.     function aP_depack_asm_fast(source: packed_data;
  43.                destination: unpacked_data) return integer;
  44.      pragma Import(C, aP_depack_asm_fast, "aP_depack_asm_fast");
  45.  
  46.     begin
  47.       if aP_depack_asm_fast(source, destination)=0 then
  48.         raise unpack_failed;
  49.       end if;
  50.     end Depack;
  51.  
  52. end aPLib;
  53.